package main.java.com.example.mainstream.utils;


import com.example.shopapp.bean.Order;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

public class Utils {
    public static String DETAIL_ADDRESS = "";
    public static String ADDRESS = "";
    public static String address_id = "";
    public static List<Order> orderList = new ArrayList<>();
    public  static String[] stypeStr = new String[]{"水果类","农作物类","粮食", "瓜果", "油", "肉类", "蔬菜类", "海鲜", "其他"};

    public static int getGoodIdByGoods(Order goods){
        if (orderList.size() ==0){
            return 0;
        }
        for (int i = 0; i < orderList.size(); i++) {
            if (goods.getTitle().equals(orderList.get(i).getTitle())
                    && goods.getTime().equals(orderList.get(i).getTime())
            && goods.getContent().equals(orderList.get(i).getContent())){
                return i;
            }
        }
        return 0;
    }

    /**
     * 是否是手机号 true 是 false 不是
     * @param input
     * @return
     */
    public static boolean isPhoneNumber(String input) {
        String regex = "^[1][3-9]\\d{9}$"; // 中国大陆手机号码格式
        return Pattern.matches(regex, input);
    }
    /**
     * 是否是邮箱 true 是 false 不是
     * @param input
     * @return
     */
    public static boolean isEmailAddress(String input) {
        String regex = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"; // 常见邮箱格式
        return Pattern.matches(regex, input);
    }
    public static String getTime(){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Date curDate = new Date(System.currentTimeMillis());
        String str = formatter.format(curDate);
        return str;
    }

}
